function Sample(id){
	this.id = id;
	this.dataSource = null;
	this.grid = null;
	
	this.init();
}

Sample.prototype.init = function(){
	this.createDataSource();
    this.createGrid();
}

Sample.prototype.createDataSource = function(){
	var _id = this.id;
	
	this.dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "/cms-vh/sample/search",
                dataType: "json",
                type: "post",
                data : {
                }
            },
            destroy: {
                url: "/cms-vh/sample/delete",
                dataType: "json",
                type: "post"
            },
            parameterMap: function(options, operation) {
                return options;
            }
        },
        change: function (e, data) {		
            if(e.action == "remove")
                $("#" + _id).data("kendoGrid").dataSource.sync();	
        },
        sync: function (e, data) {		
        	$("#" + _id).data("kendoGrid").dataSource.read();
        },
        pageSize: 5,
        batch: true,
        serverPaging: true,
        serverSorting: true,
        schema: {
            data: "results",
            total: function(data) {
                return data.total;
            },           
            model: {
                id: "id",
                fields: {
                    id: { editable: true}
                }
            }
        },	
        requestStart: function(e) {   
            var data = {
                username: $("#username").val(),
                fullname: $("#fullName").val()
            };
            
            e.sender.transport.options.read.data = data;
        }
    });
}

Sample.prototype.createGrid = function(){
	this.grid = $("#" + this.id).kendoGrid(
	{
        dataSource: this.dataSource,
        pageable: true,
        columns: [
        {
            field:"_index",
            title:" ",
            width: 40,
            sortable:false
        },{
            field:"username",
            title:"Username",
            width: 150,
            template: "<a href='/cms-vh/sample/create?id=${id}'>${username}</a>"
        },{
            field:"username",
            title:"Full name",
            width: 150,
            sortable:false,
            template: '${firstname} ${lastname}'
        },{ 
            command: ["destroy"], title: "", width: 100 
        },{
        	title:"",
            field:"",   
            template: ''
        }],
        sortable:true,
        selectable: 'row',
        editable: {
        	update: false,
            destroy: true,				
            confirmation: "Are you sure you want to remove this item ?"
        },
    });	
}

Sample.prototype.refresh = function(){
	this.dataSource.read();
}